package com.crm.system.service.impl.sys;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.permissionManagement.SysInvoiceCompanyInfo;
import com.crm.model.qo.sys.InvoiceCompanyInfoQO;
import com.crm.model.vo.sys.InvoiceCompanyInfoVO;
import com.crm.service.sys.permissionManagement.SysInvoiceCompanyInfoDbService;
import com.crm.system.service.sys.SysInvoiceCompanyInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/7/27 14:00
 */
@Service
public class SysInvoiceCompanyInfoServiceImpl implements SysInvoiceCompanyInfoService {

    @Autowired
    private SysInvoiceCompanyInfoDbService sysInvoiceCompanyInfoDbService;

    /**
     * 增加开票公司详情
     * @param invoiceCompanyInfo
     */
    @Override
    public void addInvoiceCompanyInfo(SysInvoiceCompanyInfo invoiceCompanyInfo) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        invoiceCompanyInfo.setInvoiceCompanyInfoId(CommonUtils.getGUID());
        invoiceCompanyInfo.setCreatePeopleId(userAccount.getAccountId());
        invoiceCompanyInfo.setCreateTm(new Date());
        sysInvoiceCompanyInfoDbService.addInvoiceCompanyInfo(invoiceCompanyInfo);
    }

    /**
     * 修改开票公司详情
     * @param invoiceCompanyInfo
     */
    @Override
    public void updateInvoiceCompanyInfo(SysInvoiceCompanyInfo invoiceCompanyInfo) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        invoiceCompanyInfo.setUpdatePeopleId(userAccount.getAccountId());
        invoiceCompanyInfo.setUpdateTm(new Date());
        sysInvoiceCompanyInfoDbService.updateInvoiceCompanyInfo(invoiceCompanyInfo);
    }

    /**
     * 分页查询公司详情列表
     * @param pageIndex
     * @param pageSize
     * @param invoiceCompanyInfoQO
     * @return
     */
    @Override
    public DhPageInfo<InvoiceCompanyInfoVO> selectInvoiceCompanyInfo(Integer pageIndex, Integer pageSize, InvoiceCompanyInfoQO invoiceCompanyInfoQO) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<InvoiceCompanyInfoVO> customerList = sysInvoiceCompanyInfoDbService.selectInvoiceCompanyInfo(invoiceCompanyInfoQO);
        PageInfo<InvoiceCompanyInfoVO> pageInfo = new PageInfo<InvoiceCompanyInfoVO>(customerList);
        return new DhPageInfo<InvoiceCompanyInfoVO>(pageInfo, customerList);
    }

    /**
     * 删除公司详情
     * @param invoiceCompanyInfoId
     */
    @Override
    public void delInvoiceCompanyInfo(String invoiceCompanyInfoId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        SysInvoiceCompanyInfo invoiceCompanyInfo = new SysInvoiceCompanyInfo();
        invoiceCompanyInfo.setInvoiceCompanyInfoId(invoiceCompanyInfoId);
        invoiceCompanyInfo.setDeleteStatus(1);
        invoiceCompanyInfo.setUpdatePeopleId(userAccount.getAccountId());
        invoiceCompanyInfo.setUpdateTm(new Date());
        sysInvoiceCompanyInfoDbService.updateInvoiceCompanyInfo(invoiceCompanyInfo);
    }
}
